<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="" style="display: flex;justify-content: flex-end;padding: 10rpx;">
			<view class="" @tap="$fun.jump('/pageA/wallet/walletdetail?id=recharge&name=充值记录')">
				充值记录
			</view>
		</view>
		<!-- #endif -->
		<view class="navbar">
			<view v-for="(item, index) in navList" :key="index" class="nav-item"
				:class="{current: tabCurrentIndex === item.state}" @click="tabClick(item)">
				{{item.text}}
			</view>
		</view>
		<!-- 	<view class="imgPosition">
			<image src="/static/head_bg2.png" style="width: 100%;" mode="widthFix"></image>
		</view> -->
		<view class="viewPosition">
			<view class="input_box" v-if="tabCurrentIndex=='phone'">
				<view class="title">
					卡号：
				</view>
				<input type="number" v-model="code" maxlength="11" placeholder-style="font-size:30rpx"
					placeholder="请输入手机卡号">
			</view>
			<view class="input_box" v-if="tabCurrentIndex=='video'">
				<view class="title">
					账号：
				</view>
				<input type="number" v-model="code" maxlength="11" placeholder-style="font-size:30rpx"
					placeholder="请输入充值账号">
			</view>
			<block v-for="(item,index) in showList.list" :key="index">
				<view class="itemTitle">
					{{item.title}}
				</view>
				<view class="select_box">

					<view :class="activeIndex==item1.id?'select_item active':'select_item'"
						@click="clickItem(item1,index1)" v-for="(item1,index1) in item.list" :key="index1">
						<text>{{item1.num}}</text>
						<!-- <text>仅售{{item1.money}}</text> -->
					</view>
				</view>
			</block>
			<view v-html="showList.content">

			</view>
		</view>

		<view style="margin-top: 100rpx;padding: 0 20rpx;" v-html="rechargeList.content">
		</view>
		<view style="height: 50px;"></view>
		<view class="footer-btn">
			<view class="btn" @click="recharge()">
				<text>确认支付</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rechargeList: {

				},
				tabCurrentIndex: 'phone',
				activeIndex: 0,
				code: '',
				navList: [
					// {
					// 	state: 'electric',
					// 	text: '电费充值',
					// },
					{
						state: 'phone',
						text: '话费充值',
					}, {
						state: 'video',
						text: '会员充值',
					},
				],
				showList: []
			}
		},
		onLoad(option) {
			if (!option.name) {
				option.name = '生活缴费'
			}
			console.log(option.name)
			uni.setNavigationBarTitle({
				title: option.name
			})
			this.getRechargeList()
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('/pageA/wallet/walletdetail?id=recharge&name=充值记录')
		},
		methods: {
			// 充值列表
			getRechargeList() {
				this.$fun.ajax.post('Butt/rechargeList', {}).then(res => {
					if (res.code == 1) {
						this.rechargeList = res.data
						this.showList = this.rechargeList.phone;
					}
				})
				// this.$fun.ajax.post('butt/rechargeArea', {}).then(res => {
				// 	if (res.code == 1) {
				// 		// this.rechargeList = res.data
				// 		// this.showList = this.rechargeList.electric;
				// 	}
				// })
			},
			//顶部tab点击
			tabClick(item) {
				this.tabCurrentIndex = item.state;
				this.showList = this.rechargeList[item.state];
				console.log(this.showList)
			},
			// 选择套餐
			clickItem(item, index) {
				this.activeIndex = item.id
				console.log(item)
			},
			recharge() {
				if (!this.code) {
					this.$fun.msg('请输入充值卡号卡号')
					return
				}
				if (this.activeIndex == null) {
					this.$fun.msg('请选择套餐')
					return
				}
				this.$fun.ajax.post('butt/rechargeCreate', {
					id: this.activeIndex,
					account: this.code,
					type: this.rechargeList[this.tabCurrentIndex].id
				}).then(res => {
					if (res.code == 1) {
						this.$fun.jump(`/pageB/pay?oid=${res.data}`, 2, 0)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #FFFFFF
	}

	.cont_positon {
		padding: calc(20rpx + var(--status-bar-height)) 25rpx 0;
		height: calc(100rpx + var(--status-bar-height));
	}

	.head-info {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 10;
		width: 100%;
		/* #ifdef APP-PLUS||H5 */
		padding: calc(20rpx + var(--status-bar-height)) 25rpx 0;
		height: calc(100rpx + var(--status-bar-height));
		/* #endif */
		/* #ifdef MP */
		padding: 0 25rpx;
		height: 170rpx;
		/* #endif */
		// background: url(/static/head_bg1.png) no-repeat;
		// background-size: 100% 433rpx;
		background-color: #FFFFFF;
		overflow: hidden;
		position: relative;

		.bg {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 10;
			width: 100vw;
			height: calc(100rpx + var(--status-bar-height));
		}

		.head-search {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.icon-info {
				display: flex;
				align-items: center;
				height: 100%;
				z-index: 11;

				text {
					font-size: 52rpx;
					color: #f6f6f6;
				}

				image {
					width: 42rpx;
					height: 43rpx;
				}
			}

			.search {
				display: flex;
				align-items: center;
				// width: 100%;
				padding: 0 20rpx;
				height: 65rpx;
				text-align: center;
				justify-content: center;
				z-index: 11;
				// background-color: rgba(255,255,255,0.3);
				// border-radius: 10rpx;
				color: #FFFFFF;

				.icon {
					display: flex;
					align-items: center;
					margin-right: 20rpx;

					image {
						width: 27rpx;
						height: 29rpx;
					}
				}

				.hint {
					display: flex;
					align-items: center;

					.max {
						font-size: 30rpx;
						font-weight: bold;
						color: #FFFFFF;
					}

					.min {
						font-size: 24rpx;
						color: #F6f6f6;
						margin-left: 10rpx;
					}
				}
			}
		}

		.classify-list {
			white-space: nowrap;
			width: 100%;
			height: 100rpx;
			overflow-x: auto;
			overflow-y: hidden;

			.list {
				position: relative;
				display: inline-block;
				width: 20%;
				height: 100%;
				line-height: 100rpx;
				text-align: center;

				text {
					font-size: 28rpx;
					color: #FFFFFF;
					opacity: 0.8;
				}

				.line {
					position: absolute;
					left: 50%;
					bottom: 20rpx;
					width: 60%;
					height: 8rpx;
					background: linear-gradient(to right, #f8f893, #fe9d00);
					border-radius: 10rpx;
					transform: translate(-50%, 0);
				}
			}

			.action {
				text {
					font-size: 32rpx;
					opacity: 1;
				}
			}
		}
	}

	.viewPosition {
		// position: absolute;
		// top: calc(100rpx + var(--status-bar-height) + 50rpx);
		margin: 0 30rpx;
		border-radius: 20rpx;
		width: calc(100vw - 60rpx);
		min-height: 500rpx;
		background: #FFFFFF;
		padding: 20rpx;

		.input_box {
			display: flex;
			align-items: center;
			padding-bottom: 30rpx;
			border-bottom: 1px solid #EEEEEE;

			.title {
				font-size: 30rpx;
				font-family: Adobe Heiti Std;
				font-weight: normal;
				color: #333333;
			}

			input {
				font-weight: bold;
				font-size: 42rpx;
				font-family: FZLanTingHeiS-B-GB;
				font-weight: 400;
			}
		}

		.select_box {
			margin-top: 54rpx;
			display: flex;
			flex-wrap: wrap;

			.select_item {
				margin-right: 29rpx;
				margin-bottom: 28rpx;
				width: 197rpx;
				height: 130rpx;
				border: 2rpx solid #EEEEEE;
				border-radius: 10rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				text:nth-child(1) {
					font-size: 28rpx;
					font-family: FZLanTingHeiS-B-GB;
					font-weight: bold;
					color: #FF4C15;
				}

				text:nth-child(2) {
					font-size: 22rpx;
					font-family: Microsoft YaHei UI;
					font-weight: bold;
					color: #1B85FB;
				}
			}

			.select_item:nth-child(3n+3) {
				margin-right: 0;
				width: 197rpx;
				height: 130rpx;
				border-radius: 10rpx;
			}

			.active {
				border: 2rpx solid #FF4C15;
				background: rgba(255, 76, 21, .2);
			}
		}
	}

	.footer-btn {
		position: fixed;
		left: 0;
		bottom: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 80%;
			height: 70rpx;
			background: linear-gradient(to right, $base, $change-clor);
			border-radius: 70rpx;
			box-shadow: 0 10rpx 10rpx $base;

			text {
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}

	.navbar {
		display: flex;
		height: 40px;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, .06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: $font-color-dark;
			position: relative;

			&.current {
				color: $base-color;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}

	.itemTitle {
		margin-top: 30rpx;
		font-weight: bold;
	}
</style>